package com.zmn.plat.services.impl.service.category;

import java.util.Collections;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.service.category.ItemCategory;
import com.zmn.plat.model.entity.service.category.ItemCategoryQuery;
import com.zmn.plat.persistence.interfaces.service.category.ItemCategoryDao;
import com.zmn.plat.services.interfaces.service.category.ItemCategoryService;

@Service
public class ItemCategoryServiceImpl implements ItemCategoryService {

    @Resource
    ItemCategoryDao faultCategoryDao;

    @Override
    public ItemCategory findByKey(Integer categId) {
        return faultCategoryDao.findByKey(categId);
    }

    @Override
    public List<ItemCategory> listByKeys(List<Integer> categIdList) {
        if (CollectionUtils.isEmpty(categIdList)) {
            return Collections.emptyList();
        }
        return faultCategoryDao.listByKeys(categIdList);
    }

    @Override
    public List<ItemCategory> listPageByQuery(ItemCategoryQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return faultCategoryDao.listPageByQuery(query);
    }

    @Override
    public List<ItemCategory> listByQuery(ItemCategoryQuery query) {
        return faultCategoryDao.listByQuery(query);
    }

    @Override
    public List<ItemCategory> listAll() {
        return faultCategoryDao.listAll();
    }

    @Override
    public Integer countByQuery(ItemCategoryQuery query) {
        return faultCategoryDao.countByQuery(query);
    }

    @Override
    public Integer findMaxSort() {
        return faultCategoryDao.findMaxSort();
    }

    @Override
    public Integer updateStatusByKey(ItemCategory faultCategory) {
        return faultCategoryDao.updateStatusByKey(faultCategory);
    }

    @Override
    public Integer updateStatusBatchByKey(List<Integer> ids, Integer status, String mcStaffName) {
        return faultCategoryDao.updateBatchStatusByKey(ids, status, mcStaffName);
    }

    @Override
    public Integer updateSortByKey(ItemCategory faultCategory) {
        return faultCategoryDao.updateSortByKey(faultCategory);
    }

    @Override
    public Integer updateSortByKey(Integer categId, Integer sort, String mcStaffName) {
        ItemCategory faultCategory = new ItemCategory();
        faultCategory.setCategId(categId);
        faultCategory.setSort(sort);
        faultCategory.setUpdater(mcStaffName);
        faultCategory.setUpdateTime(DateUtil.getNow());

        return updateSortByKey(faultCategory);
    }

    @Override
    public Integer updateFirstLetterByKey(Integer categId, String firstLetter, String mcStaffName) {
        ItemCategory faultCategory = new ItemCategory();
        faultCategory.setCategId(categId);
        faultCategory.setFirstLetter(firstLetter);
        faultCategory.setUpdater(mcStaffName);
        faultCategory.setUpdateTime(new Date());
        return faultCategoryDao.updateFirstLetterByKey(faultCategory);
    }

    @Override
    public Integer updateByKey(ItemCategory faultCategory) {
        return faultCategoryDao.updateByKey(faultCategory);
    }

    @Override
    public Integer insert(ItemCategory faultCategory) {
        return faultCategoryDao.insert(faultCategory);
    }

    @Override
    public Integer deleteByKey(Integer categId) {
        return faultCategoryDao.deleteByKey(categId);
    }

}